<?php

class Administration_Model_Mapper_Players extends Jnd_Model_Mapper_Abstract
{
    protected $_dict = array(
        'id' => 'idplayers', 
        'idTeams' => 'idteams', 
        'lastname' => 'lastname', 
        'firstname' => 'firstname', 
        'nickname' => 'nickname', 
        'number' => 'number', 
        'height' => 'height', 
        'weight' => 'weight', 
        'shoots' => 'shoots', 
        'born' => 'born', 
        'pictures' => 'pictures',
    	'creationUser' => 'creationuser',
    	'creationDate' => 'creationdate'
    );
    
    protected $_dictDate = array(
        'born' => 'born',
    	'creationDate' => 'creationdate'
    );
    
    
	
    /* (non-PHPdoc)
     * @see Jnd_Model_Mapper_Abstract::recuperationDonneesDepuisModel()
     */
    protected function recuperationDonneesDepuisModel( Jnd_Model_Abstract $objetModel )
    {
		$donnees = parent::recuperationDonneesDepuisModel($objetModel);
		if ( is_null($donnees['pictures']) ) {
			unset($donnees['pictures']);
		}        
		return $donnees;
    }

	/**
     * Methode permettant de générer le Table_Select pour le datagrid
     * @see Jnd_Model_Mapper_Abstract::getListSelect()
     */
    public function getListSelect( $values, $environnement, $identite, $options = null )
    {
        $table = $this->_getTable();
        $clientName = $table->info(Zend_Db_Table_Abstract::NAME);
        $dba = $table->getAdapter();
        $select = $dba->select()->from($clientName, $this->_dict, $table->info(Zend_Db_Table_Abstract::SCHEMA));

        $champ = 'libelleClient';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' LIKE ?', '%' . $values[$champ] . '%');
        }
        $champ = 'prospect';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' = ?', $values[$champ]);
        }
        $champ = 'codeAnael';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' LIKE ?', $values[$champ] . '%');
        }
        $champ = 'statutId';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' = ?', $values[$champ]);
        }
        $champ = 'codePostal';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' = ?', $values[$champ]);
        }
        $champ = 'localite';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' LIKE ?', '%' . $values[$champ] . '%');
        }
        $champ = 'creationUtilisateur';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' LIKE ?', $values[$champ] . '%');
        }
        $champ = 'creationDate';
        if (isset($values[$champ]) && $values[$champ]) {
            $dt = new Jnd_Date($values[$champ], null, 'fr_FR');
            $select->where('DATE(' . $dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ') = ?', $dt->getDbDate());
        }
        //      echo $select;
        //        die("Select : $select");
        return $select;
    }
}
